/*******************************************************************
*
*    DESCRIPTION:xmlutil.cpp--implement some function about xml
*
*    AUTHOR:
*
*    HISTORY:
*
*    DATE:8/21/2006
*
*******************************************************************/
#include "head.h"
#include "xmlutil.h"
#include "config.h"
/*
 *Function Name:xmlInit
 *
 *Parameters:
 *
 *Description:paser the configure file
 *
 *Returns:the pointer to xmlDoc
 *
 */
xmlDocPtr XmlInit(const char *confpath)
{
	xmlDocPtr doc;
	doc = xmlParseFile(confpath);

	if ( doc == NULL )
	{
		fprintf(stderr,"Document not parsed successfully. \n");
		return NULL;
	}

	return doc;
}

/*
 *Function Name:GetNodeSet
 *
 *Parameters:
 *
 *Description:get xpathobject by doc and xpath name
 *
 *Returns:pointer to XPATHOBJECT
 *
 */
xmlXPathObjectPtr GetNodeSet(xmlDocPtr doc, xmlChar *xpath)
{

	xmlXPathContextPtr context;
	xmlXPathObjectPtr result;

	context = xmlXPathNewContext(doc);
	if ( context == NULL )
	{
		printf("Error in xmlXPathNewContext\n");
		return NULL;
	}
	result = xmlXPathEvalExpression(xpath, context);
	xmlXPathFreeContext(context);
	if ( result == NULL )
	{
		printf("Error in xmlXPathEvalExpression\n");
		return NULL;
	}
	if ( xmlXPathNodeSetIsEmpty(result->nodesetval) )
	{
		xmlXPathFreeObject(result);
		printf("No result\n");
		return NULL;
	}
	return result;
}
/*
 *Function Name:IsFirstStart
 *
 *Parameters:
 *
 *Description:Read the configure file and find out if the application
 *is started in first time.
 *
 *Returns:1--it's first time	0--user has started the app before
 *
 */
int IsFirstStart(xmlDocPtr pdoc)
{
	xmlChar *xpath = (xmlChar *)"//isfirsttime";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	xmlChar *sconf;
	result = GetNodeSet(pdoc, xpath);
	assert(result != NULL);
	nodeset = result->nodesetval;
	sconf = xmlNodeListGetString(pdoc, nodeset->nodeTab[0]->xmlChildrenNode, 1);//get "YES" or "NO"
	if ( !strcmp((const char*)sconf, "yes") )
	{
#ifdef _DEBUG
		printf("IsFirstStart:yes\n");
#endif

		xmlXPathFreeObject(result);
		return 1;
	}
	else
	{

		xmlXPathFreeObject(result);
		return 0;
	}
}

/*
 *Function Name:SetHaveStarted
 *
 *Parameters:
 *
 *Description:after the software started at 1st time,mark it
 *
 *Returns:1--success 0-false
 *
 */
int SetHaveStarted(xmlDocPtr pdoc)
{
	xmlChar *xpath = (xmlChar *)"//isfirsttime";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	xmlChar *sconf;
	result = GetNodeSet(pdoc, xpath);
	if ( result )
	{
#ifdef _DEBUG
		printf("find isfirsttime\n");
#endif
		nodeset = result->nodesetval;
		xmlNodeSetContent(nodeset->nodeTab[0], (const xmlChar*)"no");

		xmlXPathFreeObject(result);

#ifdef _DEBUG
		xmlDocFormatDump(stdout, conf_xml, 1);
#endif
		xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);
		return 1;
	}
	else
	{

		xmlXPathFreeObject(result);
		return 0;
	}
}
/*
 *Function Name:SetAllowBePinged
 *
 *Parameters:allow--1,allow be pinged 0,disable
 *
 *Description:after the software started at 1st time,mark it
 *
 *Returns:1--success 0-false
 *
 */
int SetWetherAllowBePinged(xmlDocPtr pdoc, int allow)
{
	xmlChar *xpath = (xmlChar *)"//allowbeping";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	xmlChar *sconf;
	result = GetNodeSet(pdoc, xpath);
	if ( result )
	{
#ifdef _DEBUG
		printf("find allowbeping\n");
#endif
		nodeset = result->nodesetval;
		if ( allow == 0 )
		{

			xmlNodeSetContent(nodeset->nodeTab[0], (const xmlChar*)"no");
		}
		else
		{
			xmlNodeSetContent(nodeset->nodeTab[0], (const xmlChar*)"yes");
		}
		xmlXPathFreeObject(result);

#ifdef _DEBUG
		xmlDocFormatDump(stdout, conf_xml, 1);
#endif
		xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);
		return 1;
	}
	else
	{

		xmlXPathFreeObject(result);
		return 0;
	}
}

/*
 *Function Name:IsStartWithBoot
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
int IsStartwWithBoot(xmlDocPtr pdoc)
{
	xmlChar *xpath = (xmlChar *)"//startwithboot";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	xmlChar *sconf;
	result = GetNodeSet(pdoc, xpath);
	if ( result )
	{
		nodeset = result->nodesetval;
		sconf = xmlNodeListGetString(pdoc, nodeset->nodeTab[0]->xmlChildrenNode, 1);//get "YES" or "NO"
		if ( !strcmp((const char*)sconf, "yes") )
		{

			xmlXPathFreeObject(result);
			return 1;
		}
		else
		{
			xmlXPathFreeObject(result);
			return 0;
		}
	}
}
/*
 *Function Name:SetStartWithBoot
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
int SetStartWithBoot(xmlDocPtr pdoc)
{
	xmlChar *xpath = (xmlChar *)"//startwithboot";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	xmlChar *sconf;
	result = GetNodeSet(pdoc, xpath);
	if ( result )
	{
		nodeset = result->nodesetval;
		xmlNodeSetContent(nodeset->nodeTab[0], (const xmlChar*)"yes");

		xmlXPathFreeObject(result);


#ifdef _DEBUG
		xmlDocFormatDump(stdout, conf_xml, 1);
#endif
		xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);

		return 1;
	}
	else
	{
		xmlXPathFreeObject(result);
		return 0;
	}
}

/*
 *Function Name:CancelStartWithBoot
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
int CancelStartWithBoot(xmlDocPtr pdoc)
{
	xmlChar *xpath = (xmlChar *)"//startwithboot";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	xmlChar *sconf;
	result = GetNodeSet(pdoc, xpath);
	if ( result )
	{
		nodeset = result->nodesetval;
		xmlNodeSetContent(nodeset->nodeTab[0], (const xmlChar*)"no");
		xmlXPathFreeObject(result);

#ifdef _DEBUG
		xmlDocFormatDump(stdout, conf_xml, 1);
#endif
		xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);

		return 1;
	}
	else
	{
		xmlXPathFreeObject(result);
		return 0;
	}
}
/*
 *Function Name:AddAppName
 *
 *Parameters:allow--0,deny network access 1,allow
 *appname--the name of app,which is used by owner module
 *seqnum--the sequence in xml file
 *
 *Description:
 *
 *Returns:
 *
 */
int AddAppName(xmlDocPtr pdoc, int allow, char *appname, int seqnum)
{
	xmlChar *xpath = (xmlChar *)"//appname";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	result = GetNodeSet(pdoc, xpath);
	char cseqnum[5];
	memset(cseqnum, '\0', 5);
	sprintf(cseqnum, "%d", seqnum);

	if ( result )
	{
		nodeset = result->nodesetval;
		xmlNodePtr cur = nodeset->nodeTab[0];
		//update app counter
		xmlSetProp(cur, (const xmlChar*)"count", (const xmlChar*)cseqnum);
		xmlNodePtr newapp;
		//create an new app entry
		newapp = xmlNewTextChild(cur, NULL, (const xmlChar*)"app", (xmlChar*)appname);
		xmlAttrPtr attrseqnum;
		xmlAttrPtr attrallow;
		//add seqnum attr
		attrallow = xmlNewProp(newapp, (const xmlChar*)"seqnum", (const xmlChar*)cseqnum);
		//add allow attr
		if ( allow )
		{
			attrseqnum = xmlNewProp(newapp, (const xmlChar*)"allow", (const xmlChar*)"yes");
		}
		else
		{
			attrseqnum = xmlNewProp(newapp, (const xmlChar*)"allow", (const xmlChar*)"no");
		}

#ifdef _DEBUG
		xmlDocFormatDump(stdout, conf_xml, 1);
#endif
		xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);

		xmlXPathFreeObject(result);
		return 1;
	}
	else
	{
		xmlXPathFreeObject(result);

		return 0;
	}
}

/*
 *Function Name:AddServiceName
 *
 *Parameters:allow--0,deny network access 1,allow
 *appname--the name of app,which is used by owner module
 *seqnum--the sequence in xml file
 *
 *Description:
 *
 *Returns:
 *
 */
int AddServiceName(xmlDocPtr pdoc, int allow, char *service_name, int port, int seqnum)
{
	xmlChar *xpath = (xmlChar *)"//services";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	result = GetNodeSet(pdoc, xpath);
	char cseqnum[5];
	memset(cseqnum, '\0', 5);
	sprintf(cseqnum, "%d", seqnum);

	char cport[5];
	memset(cport, '\0', 5);
	sprintf(cport, "%d", port);

	if ( result )
	{
		nodeset = result->nodesetval;
		xmlNodePtr cur = nodeset->nodeTab[0];
		//update app counter
		xmlSetProp(cur, (const xmlChar*)"count", (const xmlChar*)cseqnum);
		xmlNodePtr newapp;
		//create an new app entry
		newapp = xmlNewTextChild(cur, NULL, (const xmlChar*)"serv", (xmlChar*)service_name);
		xmlAttrPtr attrseqnum;
		xmlAttrPtr attrport;
		xmlAttrPtr attrallow;
		//add seqnum attr
		attrallow = xmlNewProp(newapp, (const xmlChar*)"seqnum", (const xmlChar*)cseqnum);
		//add port attr
		attrport = xmlNewProp(newapp, (const xmlChar*)"port", (const xmlChar*)cport);
		//add allow attr
		if ( allow )
		{
			attrseqnum = xmlNewProp(newapp, (const xmlChar*)"allow", (const xmlChar*)"yes");
		}
		else
		{
			attrseqnum = xmlNewProp(newapp, (const xmlChar*)"allow", (const xmlChar*)"no");
		}

#ifdef _DEBUG
		xmlDocFormatDump(stdout, conf_xml, 1);
#endif
		xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);

		xmlXPathFreeObject(result);
		return 1;
	}
	else
	{
		xmlXPathFreeObject(result);

		return 0;
	}
}
/*
 *Function Name:GetServiceCounter
 *
 *Parameters:
 *
 *Description:read the total number of app from xml file
 *
 *Returns:the counter
 *
 */
int GetServiceCounter(xmlDocPtr pdoc)
{
	xmlChar *xpath = (xmlChar *)"//services";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	result = GetNodeSet(pdoc, xpath);
	assert(result != NULL);
	nodeset = result->nodesetval;
	xmlNodePtr cur = nodeset->nodeTab[0];
	xmlChar *counter = xmlGetProp(cur, (const xmlChar *)"count");
	int ret = atoi((const char*)counter);
	xmlXPathFreeObject(result);
	xmlFree(counter);
	return ret;
}
/*
 *Function Name:GetAppCounter
 *
 *Parameters:
 *
 *Description:read the total number of app from xml file
 *
 *Returns:the counter
 *
 */
int GetAppCounter(xmlDocPtr pdoc)
{
	xmlChar *xpath = (xmlChar *)"//appname";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	result = GetNodeSet(pdoc, xpath);
	assert(result != NULL);
	nodeset = result->nodesetval;
	xmlNodePtr cur = nodeset->nodeTab[0];
	xmlChar *counter = xmlGetProp(cur, (const xmlChar *)"count");
	int ret = atoi((const char*)counter);
	xmlXPathFreeObject(result);
	xmlFree(counter);
	return ret;
}
/*
 *Function Name:InitAppConfArray
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
void InitAppConfArray(xmlDocPtr pdoc)
{
	app_counter = GetAppCounter(pdoc);
	xml_app_counter = app_counter;
	xmlChar *xpath = (xmlChar *)"//app";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	result = GetNodeSet(pdoc, xpath);

	if ( result )
	{
		nodeset = result->nodesetval;
		assert( nodeset->nodeNr <= MAX_APP);
		for ( i = 0; i < nodeset->nodeNr; i++ )
		{
			app_conf[i].tcplink_counter = 0;
			app_conf[i].name = (char *)xmlNodeListGetString(pdoc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
#ifdef _DEBUG
			printf("In InitAppConfArray:the init apps are:%s\n", (char *)app_conf[i].name);
#endif
			xmlChar *cseqnum = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"seqnum");
			xmlChar *callow = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"allow");
#ifdef _DEBUG
			printf("name:%s, seqnum:%s, allow:%s\n", app_conf[i].name, cseqnum, callow);
#endif
			assert(app_conf[i].name != NULL && cseqnum != NULL && callow != NULL);
			app_conf[i].seqnum = atoi((const char*)cseqnum);

			if ( strcmp((const char*)callow, "yes") == 0 )
			{
				app_conf[i].allow = 1;
			}
			else
			{
				app_conf[i].allow = 0;
			}
			xmlFree(cseqnum);
			xmlFree(callow);
		}
		assert(app_counter == i);
	}

	xmlXPathFreeObject(result);
}

/*
 *Function Name:InitServiceConfArray
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
void InitServiceConfArray(xmlDocPtr pdoc)
{
	service_counter = GetServiceCounter(pdoc);
	xmlChar *xpath = (xmlChar *)"//serv";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	result = GetNodeSet(pdoc, xpath);

	if ( result )
	{
		nodeset = result->nodesetval;
		assert( nodeset->nodeNr <= MAX_APP);
		for ( i = 0; i < nodeset->nodeNr; i++ )
		{
			service_conf[i].name = (char *)xmlNodeListGetString(pdoc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
#ifdef _DEBUG
			printf("In InitServiceConfArray:the init apps are:%s\n", (char *)service_conf[i].name);
#endif
			xmlChar *cseqnum = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"seqnum");
			xmlChar *callow = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"allow");
			xmlChar *csport = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"port");
#ifdef _DEBUG
			printf("name:%s, seqnum:%s, allow:%s\n", service_conf[i].name, cseqnum, callow);
#endif
			assert(app_conf[i].name != NULL && cseqnum != NULL && callow != NULL);
			service_conf[i].seqnum = atoi((const char*)cseqnum);
			service_conf[i].sport = atoi((const char*)csport);

			if ( strcmp((const char*)callow, "yes") == 0 )
			{
				service_conf[i].allow = 1;
			}
			else
			{
				service_conf[i].allow = 0;
			}

			xmlFree(cseqnum);
			xmlFree(callow);
			xmlFree(csport);
		}
		assert(service_counter == i);
	}

	xmlXPathFreeObject(result);
}

/*
 *Function Name:XmlInitAppListStore
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
void XmlInitAppListStore(GtkListStore *app_list_store)
{
	xmlChar *xpath = (xmlChar *)"//app";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	gboolean b_allow = 0;
	xmlChar *cseqnum;
	xmlChar *callow;
	result = GetNodeSet(conf_xml, xpath);
	if ( result )
	{
		nodeset = result->nodesetval;
		if ( nodeset->nodeNr > MAX_APP )
		{
			printf("In XmlInitAppListStore:Too much app in xml file\n");
		}
		for ( i = 0; i < nodeset->nodeNr; i++ )
		{

			char *app_name = (char *)xmlNodeListGetString(conf_xml, nodeset->nodeTab[i]->xmlChildrenNode, 1);//needn't to be free

			cseqnum = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"seqnum");//must free
			int seq_num = atoi((const char*)cseqnum);

			callow = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"allow");//must free

			if ( strcmp((const char*)callow, "yes") == 0 )
			{
				b_allow = 1;
			}
			else
			{
				b_allow = 0;
			}
			//add to list_store
			GtkTreeIter iter;
			gtk_list_store_append(app_list_store, &iter);
			gtk_list_store_set(app_list_store, &iter, 0, app_name, 2, b_allow, -1);

			xmlFree(cseqnum);
			xmlFree(callow);
		}
	}
	xmlXPathFreeObject(result);
}
/*
 *Function Name:XmlInitServiceListStore
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
void XmlInitServiceListStore(GtkListStore *service_list_store)
{

	xmlChar *xpath = (xmlChar *)"//serv";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	gboolean b_allow = 0;
	xmlChar *cseqnum;
	xmlChar *callow;
	xmlChar *csport;
	result = GetNodeSet(conf_xml, xpath);
	if ( result )
	{
		nodeset = result->nodesetval;
		if ( nodeset->nodeNr > MAX_APP )
		{
			printf("In XmlInitAppListStore:Too much app in xml file\n");
		}
		for ( i = 0; i < nodeset->nodeNr; i++ )
		{

			char *app_name = (char *)xmlNodeListGetString(conf_xml, nodeset->nodeTab[i]->xmlChildrenNode, 1);

			cseqnum = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"seqnum");
			csport = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"port");
			int seq_num = atoi((const char*)cseqnum);

			callow = xmlGetProp(nodeset->nodeTab[i], (const xmlChar *)"allow");

			if ( strcmp((const char*)callow, "yes") == 0 )
			{
				b_allow = 1;
			}
			else
			{
				b_allow = 0;
			}
			//add to list_store
			gtk_list_store_clear(service_list_store);
			GtkTreeIter iter;
			gtk_list_store_append(service_list_store, &iter);
			gtk_list_store_set(service_list_store, &iter, 0, app_name, 2, csport, 3, b_allow, -1);

			xmlFree(cseqnum);
			xmlFree(callow);
			xmlFree(csport);
		}
	}
	xmlXPathFreeObject(result);
}
/*
 *Function Name:XmlAllowApp
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
void XmlAllowApp(char *app_name)
{

	xmlChar *xpath = (xmlChar *)"//app";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	gboolean b_allow = 0;
	xmlAttrPtr allow_attr;
	result = GetNodeSet(conf_xml, xpath);

	if ( result )
	{
		nodeset = result->nodesetval;

		for ( i = 0; i < nodeset->nodeNr; i++ )
		{

			xmlChar *temp = xmlNodeListGetString(conf_xml, nodeset->nodeTab[i]->xmlChildrenNode, 1);

			if ( strcmp(app_name, (char *)temp) == 0 )
			{
				xmlSetProp(nodeset->nodeTab[i], (const xmlChar *)"allow", (const xmlChar *)"yes");
			}
		}
	}
	else
	{
		printf("can't find app\n");
	}

#ifdef _DEBUG
	xmlDocFormatDump(stdout, conf_xml, 1);
#endif
	xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);

	xmlXPathFreeObject(result);

}

/*
 *Function Name:XmlAllowService
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
void XmlAllowService(char *service_name)
{

	xmlChar *xpath = (xmlChar *)"//serv";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	gboolean b_allow = 0;
	xmlAttrPtr allow_attr;
	result = GetNodeSet(conf_xml, xpath);

	if ( result )
	{
		nodeset = result->nodesetval;

		for ( i = 0; i < nodeset->nodeNr; i++ )
		{

			xmlChar *temp = xmlNodeListGetString(conf_xml, nodeset->nodeTab[i]->xmlChildrenNode, 1);

			if ( strcmp(service_name, (char *)temp) == 0 )
			{
				xmlSetProp(nodeset->nodeTab[i], (const xmlChar *)"allow", (const xmlChar *)"yes");
			}
		}
	}
	else
	{
		printf("can't find app\n");
	}

#ifdef _DEBUG
	xmlDocFormatDump(stdout, conf_xml, 1);
#endif
	xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);

	xmlXPathFreeObject(result);

}


/*
 *Function Name:XmlDenyApp
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
void XmlDenyApp(char *app_name)
{

	xmlChar *xpath = (xmlChar *)"//app";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	gboolean b_allow = 0;
	xmlAttrPtr allow_attr;
	result = GetNodeSet(conf_xml, xpath);

	if ( result )
	{
		nodeset = result->nodesetval;

		for ( i = 0; i < nodeset->nodeNr; i++ )
		{
			xmlChar *temp = xmlNodeListGetString(conf_xml, nodeset->nodeTab[i]->xmlChildrenNode, 1);

			if ( strcmp(app_name, (char *)temp) == 0 )
			{
				xmlSetProp(nodeset->nodeTab[i], (const xmlChar *)"allow", (const xmlChar *)"no");
			}
		}
	}

#ifdef _DEBUG
	xmlDocFormatDump(stdout, conf_xml, 1);
#endif
	xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);

	xmlXPathFreeObject(result);

}

/*
 *Function Name:XmlDenyService
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
void XmlDenyService(char *service_name)
{

	xmlChar *xpath = (xmlChar *)"//serv";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	gboolean b_allow = 0;
	xmlAttrPtr allow_attr;
	result = GetNodeSet(conf_xml, xpath);

	if ( result )
	{
		nodeset = result->nodesetval;

		for ( i = 0; i < nodeset->nodeNr; i++ )
		{
			xmlChar *temp = xmlNodeListGetString(conf_xml, nodeset->nodeTab[i]->xmlChildrenNode, 1);

			if ( strcmp(service_name, (char *)temp) == 0 )
			{
				xmlSetProp(nodeset->nodeTab[i], (const xmlChar *)"allow", (const xmlChar *)"no");
			}
		}
	}

#ifdef _DEBUG
	xmlDocFormatDump(stdout, conf_xml, 1);
#endif
	xmlSaveFormatFile(CONFIG_PATH, conf_xml, 0);

	xmlXPathFreeObject(result);
}
